

#====================================================================
#
#		DEFAULT COMMAND IMPLEMENTATION
#			GET, HEAD, OPTIONS, PUT, POST, DELETE
#
#====================================================================


#--------------------------------------------------------------------
Function Process-Web-GET
{
	param
	(
		  [psobject] $WebRequest
	)

	[psobject] $WebResponse = New-WebResponse
	$WebResponse.WebRequest		= $WebRequest
	$WebResponse.Resource		= $null
	$WebResponse.ResponseCode	= "501 Not Implemented"
	
	# Construct the request path.
	[string] $ResourcePath = $WebRequest.WebServer.ApplicationFolder
	[string] $ResourceName = $WebRequest.ResourceName

	# Check if requested path is a directory.
	if( Test-Path -Path $( $ResourcePath + "\" + $ResourceName ) -PathType container )
	{
		# Check for a default file.
		if( Test-Path -Path $( $ResourcePath + "\" + $ResourceName + "\index.htm" ) -PathType leaf )
			{ $ResourceName += "\index.htm" }
		elseif( Test-Path -Path $( $ResourcePath + "\" + $ResourceName + "\index.html" ) -PathType leaf )
			{ $ResourceName += "\index.html" }
		elseif( Test-Path -Path $( $ResourcePath + "\" + $ResourceName + "\default.htm" ) -PathType leaf )
			{ $ResourceName += "\default.htm" }
		elseif( Test-Path -Path $( $ResourcePath + "\" + $ResourceName + "\default.html" ) -PathType leaf )
			{ $ResourceName += "\default.html" }
		else
			{ $WebResponse.ResponseCode = "405 Method Not Allowed" }
	}

	# Check if requested path is a file.
	if( Test-Path -Path $( $ResourcePath + "\" + $ResourceName ) -PathType leaf )
	{
		# Resource is a file
		$WebResponse.Resource = Read-Resource $ResourcePath $ResourceName
		$WebResponse.ResponseCode = "200 OK"
	}

	if( $WebResponse.Resource -eq $null )
	{
		# Not found
		$WebResponse.ResponseCode = "404 Not Found"
	}
	
	# Send the response.
	[bool] $b = Send-WebResponse $WebResponse $true
	if( $b -eq $false ) { return $false }

	# Return, OK
	return $true
}


#--------------------------------------------------------------------
Function Process-Web-HEAD
{
	param
	(
		  [psobject] $WebRequest
	)

	[psobject] $WebResponse = New-WebResponse
	$WebResponse.WebRequest		= $WebRequest
	$WebResponse.Resource		= $null
	$WebResponse.ResponseCode	= "501 Not Implemented"
	
	# Send the response header.
	[bool] $b = Send-WebResponseHeader $WebResponse
	if( $b -eq $false ) { return $false }

	return $true

}


#--------------------------------------------------------------------
Function Process-Web-OPTIONS
{
	param
	(
		  [psobject] $WebRequest
	)

	[psobject] $WebResponse = New-WebResponse
	$WebResponse.WebRequest		= $WebRequest
	$WebResponse.Resource		= $null
	$WebResponse.ResponseCode	= "501 Not Implemented"
	
	# Send the response header.
	[bool] $b = Send-WebResponseHeader $WebResponse
	if( $b -eq $false ) { return $false }

	return $true

}


#--------------------------------------------------------------------
Function Process-Web-PUT
{
	param
	(
		  [psobject] $WebRequest
	)

	[psobject] $WebResponse = New-WebResponse
	$WebResponse.WebRequest		= $WebRequest
	$WebResponse.Resource		= $null
	$WebResponse.ResponseCode	= "501 Not Implemented"
	
	# Send the response header.
	[bool] $b = Send-WebResponseHeader $WebResponse
	if( $b -eq $false ) { return $false }

	return $true

}


#--------------------------------------------------------------------
Function Process-Web-POST
{
	param
	(
		  [psobject] $WebRequest
	)

	[psobject] $WebResponse = New-WebResponse
	$WebResponse.WebRequest		= $WebRequest
	$WebResponse.Resource		= $null
	$WebResponse.ResponseCode	= "501 Not Implemented"
	
	# Send the response header.
	[bool] $b = Send-WebResponseHeader $WebResponse
	if( $b -eq $false ) { return $false }

	return $true

}


#--------------------------------------------------------------------
Function Process-Web-DELETE
{
	param
	(
		  [psobject] $WebRequest
	)

	[psobject] $WebResponse = New-WebResponse
	$WebResponse.WebRequest		= $WebRequest
	$WebResponse.Resource		= $null
	$WebResponse.ResponseCode	= "501 Not Implemented"
	
	# Send the response header.
	[bool] $b = Send-WebResponseHeader $WebResponse
	if( $b -eq $false ) { return $false }

	return $true

}

